<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item,index) in tabbarList" :key="item.id" :class="[item.centerItem ? ' center-item' : '']"
			 @click="changeItem(item)">
				<view class="item-top">
					<image :src="currentItem==item.id?item.selectIcon:item.icon"></image>
				</view>
				<view class="item-bottom" :class="[currentItem==item.id ? 'item-active' : '']">
					<text>{{item.text}}</text>
				</view>
			</view>
		</block>

	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				currentItem: 0,
				tabbarList: [{
						id: 0,
						path: "/pages/main/index",
						icon: "/static/tabbar/index.png",
						selectIcon: "/static/tabbar/index3.png",
						text: "首页",
						centerItem: false
					}, {
						id: 1,
						path: "/pages/main/category",
						icon: "/static/tabbar/category.png",
						selectIcon: "/static/tabbar/category3.png",
						text: "分类",
						centerItem: false
					},
					// {  
					//                    id: 2,  
					//                    path: "/pages/main/upgrade",  
					//                    icon: "/static/tabbar/upgrade.png",  
					//                    selectIcon: "/static/tabbar/upgrade.png",  
					//                    text: "升级",  
					//                    centerItem: true  
					//                },
					{
						id: 3,
						path: "/pages/main/cart",
						icon: "/static/tabbar/cart2.png",
						selectIcon: "/static/tabbar/cart3.png",
						text: "购物车",
						centerItem: false
					},
					{
						id: 4,
						path: "/pages/main/me",
						// path: "/pages/main/user",  
						icon: "/static/tabbar/user.png",
						selectIcon: "/static/tabbar/user3.png",
						text: "我的",
						centerItem: false
					}
				]

			};
		},
		mounted() {
			this.currentItem = this.currentPage;
			// uni.hideTabBar();
		},
		methods: {
			changeItem(item) {
				let _this = this;
				//_this.currentItem = item.id;  

				uni.switchTab({
					url: item.path
				});
			}
		}
	}
</script>
<style>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 110rpx;
		box-shadow: 0 0 1px #999;
		display: flex;
		align-items: center;
		padding: 5rpx 0;
		color: #262626;
		background-color: #FFFFFF;
		z-index: 100000;
	}

	.tabbar-container .tabbar-item {
		width: 33.33%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
	}

	.tabbar-container .item-active {
		color: #f81149;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
	}

	.tabbar-container .tabbar-item .item-top {
		width: 76rpx;
		height: 76rpx;
		padding: 10rpx 10rpx 2rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 120rpx;
		height: 110rpx;
		position: absolute;
		top: -40rpx;
		left: calc(50% - 55rpx);
		border-radius: 50%;
		/* box-shadow: 0 0 5px #999;  */
		box-shadow: 0 0 1px #999;
		background-color: #ffffff;
	}

	.tabbar-container .center-item .item-top::after {
		content: '';
		position: absolute;
		top: 35rpx;
		left: 0;
		display: block;
		width: 120rpx;
		height: 100rpx;
		background-color: #FFFFFF;
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
		z-index: 999;
	}

	.tabbar-container .center-item .item-top image {
		position: absolute;
		left: 10rpx;
		top: 10rpx;
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		z-index: 999;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 24rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		/* #ifdef */
		left: 8rpx;
		/* #endif */

		bottom: -6rpx;
	}
</style>
